<?php
namespace Admin\Controller;
use Think\Controller;

class IndexController extends Controller {
	protected function _initialize() {
		//===系统信息======
		$system = D('System')->find(1);
		$this->assign('system', $system);
	}
	public function index() {
		if (IS_POST) {
			//验证码
			// $verify = new \Think\Verify();
			// if (!$verify->check(I('post.passcode'))) {
			//     $this->error('验证码错误!');
			//     return false;
			// }
			//登录
			$userModel = D('User');
			if (!($userModel->create($_POST, 4) && $userModel->login('管理员'))) {
				$this->error($userModel->getError());
			}
			$this->redirect('System/index');
			return true;
		}
		if (session('管理员')) {
			$this->redirect('System/index');
		} else {
			//登录页面
			$this->display('login');
		}
	}

	// public function passcode() {
	//     $verify = new \Think\Verify(['length'=>4, 'useNoise'=>false, 'useCurve'=>false,]);
	//     echo $verify->entry();
	// }

	public function logout() {
		session('管理员', null);
		$this->success('注销成功!', U('Index/index'));
	}

}
